package com.gegao.somethinginteresting.utils.fresco;

import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;

import com.facebook.common.internal.Preconditions;
import com.facebook.drawee.drawable.ScaleTypeDrawable;
import com.facebook.drawee.drawable.ScalingUtils;

/**
 * drawable的工具类
 * Created by liuchenghui on 2016/01/27.
 */
public class DrawableUtils {

    /**
     * 设置drawble的缩放模式
     * @param drawable 图片
     * @param scaleType 缩放模式
     * @param focusPoint 焦点
     * @return {@link ScaleTypeDrawable}
     */
    public static Drawable maybeWrapWithScaleType(Drawable drawable, @Nullable ScalingUtils.ScaleType scaleType, @Nullable PointF focusPoint) {
        Preconditions.checkNotNull(drawable);
        if (scaleType == null) {
            return drawable;
        }
        ScaleTypeDrawable scaleTypeDrawable = new ScaleTypeDrawable(drawable, scaleType);
        if (focusPoint != null) {
            scaleTypeDrawable.setFocusPoint(focusPoint);
        }
        return scaleTypeDrawable;
    }
}
